import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-s','--source',required=True)
parser.add_argument('-t','--target',required=True)
parser.add_argument('-n','--num',type=int,required=True)
parser.add_argument('-e','--ext',default='.jpg',type=str,required=False)
args = parser.parse_args()

# 从源文件夹复制前1000个文件到目标文件夹
# source='/mnt/nas/datasets/diction/ZipArchive0729_human'
source=args.source
target=args.target
ext=args.ext
num=int(args.num)

# mkdir $target
# find $source -type f -print0 | head -n $num | xargs -0 cp -t $target
import shutil,os
from tqdm import tqdm
from util_for_os import osj,ose
if ose(target):shutil.rmtree(target)
os.makedirs(target)

with open( osj( source , 'names.txt' ) ) as f:
    names = f.readlines()

import random
random.shuffle(names)
for n in tqdm(names):
    n  = n.strip()
    if not n.endswith(ext):continue
    shutil.copy2( osj( source , n ) , target )
    num -= 1
    if num == 0:break
